//promise 改造异步案例：模拟ajax函数
function ajax({url = '', type = 'get', dataType = 'json'}) {
    return new Promise(((resolve, reject) => {
        let xhr = new XMLHttpRequest();
        xhr.open(type, url, true);
        xhr.responseType = dataType;
        xhr.onload = ()=>{
            if (xhr.status==200){
                resolve(xhr.response);
            }
        };
        xhr.onerror = (err)=>{
            reject(err)
        };
        xhr.send();
    }));
}